package zucc.edu.cn.chengchengparttime.Mysignup;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.appcompat.widget.AppCompatButton;
import androidx.recyclerview.widget.RecyclerView;

import java.util.List;

import zucc.edu.cn.chengchengparttime.R;
import zucc.edu.cn.chengchengparttime.Text;

public class MysignupAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
    private static final int NORMAL_VIEW=0; //兼职列表

    private Context context;
    private List<Text> dataList;

    public MysignupAdapter(List<Text> dataList,Context context){
        this.context=context;
        this.dataList=dataList;
    }

    public class NormalViewHolder extends RecyclerView.ViewHolder{
        public NormalViewHolder(View itemView){
            super(itemView);
            itemView.setOnClickListener(v -> {
            });
        }
        //数据封装
        public TextView workname;
        public TextView worktimeandarea;
        public TextView workstatus;
        public TextView salaryperhour;
        public TextView paymentway;
        public AppCompatButton btn_getPhone;
        //getter和setter方法
        public TextView getWorkname() {
            return workname;
        }

        public void setWorkname(TextView workname) {
            this.workname = workname;
        }

        public TextView getWorktimeandarea() {
            return worktimeandarea;
        }

        public void setWorktimeandarea(TextView worktimeandarea) {
            this.worktimeandarea = worktimeandarea;
        }

        public TextView getWorkstatus() {
            return workstatus;
        }

        public void setWorkstatus(TextView workstatus) {
            this.workstatus = workstatus;
        }

        public TextView getSalaryperhour() {
            return salaryperhour;
        }

        public void setSalaryperhour(TextView salaryperhour) {
            this.salaryperhour = salaryperhour;
        }

        public TextView getPaymentway() {
            return paymentway;
        }

        public void setPaymentway(TextView paymentway) {
            this.paymentway = paymentway;
        }

        public AppCompatButton getBtn_getPhone() {
            return btn_getPhone;
        }

        public void setBtn_getPhone(AppCompatButton btn_getPhone) {
            this.btn_getPhone = btn_getPhone;
        }
    }

    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        if(viewType==NORMAL_VIEW){
            View normalView= LayoutInflater.from(context).inflate(R.layout.activity_mysignup_item,null); //定义view
            NormalViewHolder Normalholder=new NormalViewHolder(normalView);
            //接下来是控件的引用声明
            Normalholder.workname=(TextView) normalView.findViewById(R.id.workname);
            Normalholder.worktimeandarea=(TextView) normalView.findViewById(R.id.worktimeandarea);
            Normalholder.workstatus=(TextView) normalView.findViewById(R.id.workstatus);
            Normalholder.salaryperhour=(TextView) normalView.findViewById(R.id.salaryperhour);
            Normalholder.paymentway=(TextView) normalView.findViewById(R.id.paymentway);
            Normalholder.btn_getPhone=(AppCompatButton) normalView.findViewById(R.id.btn_getPhone);
            return Normalholder;
        }else{
            return null;
        }
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
        try{
            if(holder instanceof MysignupAdapter.NormalViewHolder){
                MysignupAdapter.NormalViewHolder normalViewHolder=(MysignupAdapter.NormalViewHolder) holder;
                Text data=dataList.get(position);
                Log.d("data",data.toString());//测试

                //填充工作名称
                normalViewHolder.workname.setText(data.n1);
                Log.d("workname",normalViewHolder.workname.getText().toString());
                //填充工作时间、地点
                normalViewHolder.worktimeandarea.setText(data.n2);
                Log.d("worktimeandarea",normalViewHolder.worktimeandarea.getText().toString());
                //填充工作状态
                normalViewHolder.workstatus.setText(data.n3);
                Log.d("workstatus",normalViewHolder.workstatus.getText().toString());
                //填充时薪
                normalViewHolder.salaryperhour.setText(data.n4);
                Log.d("salaryperhour",normalViewHolder.salaryperhour.getText().toString());
                //填充结付方式
                normalViewHolder.paymentway.setText(data.n5);
                Log.d("paymentway",normalViewHolder.paymentway.getText().toString());
            }
        }catch (Exception e){
            e.printStackTrace();
        }
    }

    //重写getItemCount方法
    @Override
    public int getItemCount() {
        return dataList.size();
    }

    //重写getItemViewType方法
    @Override
    public int getItemViewType(int position){
        if(position>=0){
            return NORMAL_VIEW;
        }else{
            return NORMAL_VIEW;
        }
    }
}
